<template>
    <div>
        <el-form label-width="100px" :model="globalsystemconfig" ref="globalsystemconfig_ref">
            <el-form-item label="版本编号" prop="VersionNanme">
                <el-input v-model="globalsystemconfig.VersionNanme"></el-input>
                <div class="el-form-item__error">当前最新版本号{{ LastVersion.VersionNanme }}</div>
            </el-form-item>
            <el-form-item label="更新内容" prop="UpContent">
                <el-input type="textarea" v-model="globalsystemconfig.UpContent"></el-input>
            </el-form-item>
            <el-form-item label="是否强制更新" prop="mandatory_update">
                <el-radio-group v-model="globalsystemconfig.mandatory_update">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-row v-show="fileDetails_show">
                <el-col :span="12">
                    <el-form-item label="apk文件名称" prop="apk_name">
                        <el-input v-model="globalsystemconfig.apk_name" ></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="文件大小" prop="apk_size">
                        <el-input v-model="globalsystemconfig.apk_size" ></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item>
                <UploadFileF ref="UploadFileF"
                             :Addlistdata="Addlistdata"
                             :another-data="AnotherData"
                             :multiple="false"
                             btnsize="medium"
                             :upshow="false" ></UploadFileF>
            </el-form-item>
            <el-form-item align="center" label-width="0px">
                <el-button @click="submit_event" type="primary">提交</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import UploadFileF from "../../UploadFileF";

    export default {
        name: "AppSetting",
        props:{
            biaoshi:{
                Object:String,
                required:true
            }
        },
        components:{
            UploadFileF,
        },
        watch:{
            biaoshi:function () {
                this.Init()
            }
        },
        data(){
            return{
                //版本集合
                LastVersion:[],
                //数据实体
                globalsystemconfig:{
                    VersionNanme:'',
                    UpContent:'',
                    apk_url:'',
                    apk_name:'',
                    apk_size:'',
                    mandatory_update:true
                },
                //文件上传参数
                AnotherData:{
                    FileType: 4096,
                    id: 0,
                    Type: 0,
                    Single: false,
                },
                fileDetails_show:false,
            }
        },
        mounted() {
            this.$nextTick(()=>{
                this.Init()
            })
        },
        methods:{
            //初始数据获取
            Init(){
                this.$http.get("App/GetAppInfo").then(res=>{
                    this.LastVersion = res.data.data
                })
            },
            //文件选择
            Addlistdata(){
                var list = this.$refs["UploadFileF"].fileList
                if(list.length>0){
                    this.fileDetails_show = true
                    let apkdata = list[0]
                    let apkdatatype = apkdata.name.split(".")[1]
                    if(apkdatatype == 'apk'){
                        this.globalsystemconfig.apk_name = apkdata.name.split(".")[0]
                        this.globalsystemconfig.apk_size = (apkdata.size / 1000000).toFixed(2)+"M"
                    }else{
                        this.$message.warning('请选择.apk的安装包文件!')
                        this.$refs["UploadFileF"].fileList.length = 0
                    }
                }
            },
            //提交
            submit_event(){
                if (this.globalsystemconfig.apk_name== "" || this.globalsystemconfig.apk_size ==""){
                    this.$message.warning("请选择安装包文件")
                }else{
                    this.$http.post('App/SaveAppVersion',{
                        globalsystemconfig: this.globalsystemconfig
                    }).then(res=>{
                        if (res.data.message.IsSuccess){
                            this.AnotherData.id = res.data.globalsystemconfig.id
                            this.$refs["UploadFileF"].submitUpload()
                            this.$message.success(res.data.message.Msg)
                            this.$parent.$parent.AppSetting_show = false
                            this.FromReset()
                        }else{
                            this.$message.warning(res.data.message.Msg)
                        }
                    })
                }
            },
            //表格重置
            FromReset(){
                this.$refs["globalsystemconfig_ref"].resetFields()
                this.fileDetails_show = false
                this.$refs["UploadFileF"].fileList.length = []
            }
        },
    }
</script>

<style scoped>

</style>
